#字典的定义
xiaoming={'name':"小明",'age':20,'gender':"男"}
print(xiaoming.keys())  #获取字典的键
print(xiaoming.values())  #获取字典的值
print(xiaoming.items())  #获取字典的键值对

#字典的遍历
for key in xiaoming:
    print('%s %s'%(key,xiaoming[key]))

for key,value in xiaoming.items():
    print('%s %s'%(key,value))

#字典的取值
print(xiaoming['age'])
print('`'*50)

#字典的增加和修改
xiaoming['name']='xiaowang'#如果存在键值对，就更新为新的，没有就新建一个
xiaoming['height']=1.75
for key,value in xiaoming.items():
    print('%s %s'%(key,value),end=' ')
#如果存在键值对，不会修改数据，不存在就新建一个键值对并返回值
xiaoming.setdefault('age',19)
xiaoming.setdefault('sex',666)
print(xiaoming)



print('`'*50)

#字典的删除
shanchu=xiaoming.pop('height')
print(shanchu)
del xiaoming['name']
print(xiaoming)

#统计键值对的数量
print(len(xiaoming))

#合并字典,合并后可能会覆盖之前已有的键值对
dict1={'name':'xiaohong','long':222,'jjj':990}
xiaoming.update(dict1)
print(xiaoming)
print('`'*50)
#清空字典
xiaoming.clear()
print(xiaoming)

#可以把多个字典放进列表中
dict1={'name':'xiaoxiao','qq':122333,'tel':111111}
dict2={'name':'xiaowang','age':22,'tel':222222}
list1=[dict1,dict2]
print(list1)